package com.smh.a01queryDemo01;

import java.util.ArrayList;

public class BasicSearchDemo1 {
    public static void main(String[] args) {
        //顺序查找
        int[] arr ={1,2,3,4,5,6,7,8,9,0,1,2,2,2};
        System.out.println(basicSearch(arr,2));
        System.out.println(basicSearch1(arr,2));
        System.out.println(basicSearch2(arr,2));

    }
    public static boolean basicSearch(int[] arr,int num){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==num){
                return true;
            }
        }
        return false;
    }
    public static int basicSearch2(int[] arr,int num){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==num){
                return i;
            }
        }
        return -1;
    }

    public static ArrayList<Integer> basicSearch1(int[] arr,int num){
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==num){
                arrayList.add(i);
            }
        }

        return arrayList;
    }
}
